package com.练习案例.抽奖箱;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class MyThread extends Thread{//五个人抽三个红包，红包一共一百
    ArrayList<Integer> list=new ArrayList<>();

    public MyThread(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (MyThread.class){
                if(list.size()==0){
                    break;
                }else{
                    Collections.shuffle(list);
                    Integer prize = list.remove(0);
                    System.out.println(getName()+"抽到了"+prize);
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

}
